<template>
  <div class="answers__main flex">
    <div class="answers__main__header flex-ac">
      <div class="answers__main__header__title">{{ title }}</div>
      <nav class="answers__main__header__nav flex-ac" @click="moveLine">
        <div class="item" v-for="item in nav" :key="item.id" @click="emits('update:modelValue', item.id)">{{ item.name }}
        </div>
        <span class="line"></span>
      </nav>
      <div class="answers__main__header__button btn" :class="[{ 'answers__main__header__button--hidden': !isBtn }]"
        @click="emits('sendProblem')">提问题
      </div>
    </div>
    <slot />
  </div>
</template>

<script setup lang="ts">
import { getRef } from './move';
interface INav {
  id: string,
  name: string,
}
const { line, moveLine } = getRef()

const props = withDefaults(defineProps<{ title?: string, isBtn: boolean, nav: INav[], modelValue: string }>(), {
  title: "",
  isBtn: false,
})
const emits = defineEmits(["update:modelValue", "sendProblem"]);


</script>

<style lang="scss" scoped>
.answers__main {
  flex-direction: column;
  font-family: "微软雅黑";

  &__header {
    justify-content: space-between;
    padding: 10px 0;
    color: #2C2C2C;

    &__title {
      font-size: 24px;
      font-weight: bold;
    }

    &__nav {
      gap: 40px;
      position: relative;

      .item {
        padding: 14px 0;
        font-size: 18px;
      }

      .line {
        position: absolute;
        bottom: 0;
        transition: .5s linear left;
        left: v-bind("line.x + 'px'");
        width: v-bind("line.width + 'px'");
        height: 4px;
        border-radius: 4px;
        background-color: $color;
      }
    }

    &__button {
      background-color: $color;

      &--hidden {
        width: 0;
        height: 0;
        padding: 0;
      }
    }
  }

}
</style>